#include "scripteditordialog.h"
#include "scripteditorwidget.h"

#include <QLayout>
#include <QPushButton>
#include <QSpacerItem>

ScriptEditorDialog::ScriptEditorDialog(QWidget *parent) :
    QDialog(parent)
{
    QVBoxLayout *vBoxMain = new QVBoxLayout();
    vBoxMain->setContentsMargins(5,5,5,5);
    editorWidget = new ScriptEditorWidget(this);
    vBoxMain->addWidget(editorWidget);

    QHBoxLayout *hBoxLayout = new QHBoxLayout();
    buttonOk = new QPushButton(tr("Ok"),this);
    buttonCancel = new QPushButton(tr("Cancel"),this);
    horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    hBoxLayout->addItem(horizontalSpacer);
    hBoxLayout->addWidget(buttonOk);
    hBoxLayout->addWidget(buttonCancel);

    vBoxMain->addLayout(hBoxLayout);

    connect(buttonOk,SIGNAL(clicked()),this,SLOT(accept()));
    connect(buttonCancel,SIGNAL(clicked()),this,SLOT(cancel()));


    setGeometry(50,70,900,700);

    setLayout(vBoxMain);
}


void ScriptEditorDialog::cancel()
{
    reject();
}

QString ScriptEditorDialog::scriptText() const
{
    if(editorWidget)
    {
        return editorWidget->scriptText();
    }
    return QString();
}

void ScriptEditorDialog::setScriptText(const QString &text)
{
    if(editorWidget)
    {
        editorWidget->setScriptText(text);
    }
}

#include "codeedit.h"
bool ScriptEditorDialog::findFunctionDeclaration(const QString &func)
{
    return editorWidget->editor->findFunctionDeclaration(func);
}

void ScriptEditorDialog::appendFunction(const QString &funcName, const QStringList &params)
{
    editorWidget->appendFunction(funcName,params);
}
